#include <stdio.h>

int main(int argc, char *argv[]) {

    int personNum;
    scanf("%d",&personNum);

    int people[100];
    for (size_t i = 1; i <= personNum; i++)
    {
        people[i] = i;
    }

    int tempNums = personNum;
    for (size_t i = 1,count=0; tempNums>1;)
    {
        if(people[i]!=0){
            count++;
        }

        if(count==3){
            people[i] = 0;
            count = 0;
            tempNums--;
        }
        
        if(i==personNum){
            i = 1;
            continue;
        }

        i++;
    }
    
    for (size_t i = 1; i <= personNum; i++)
    {
        if(people[i]!=0){
            printf("%d", people[i]);
        }
    }
    

    return 0;
}